package jvm;

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/8/10 17:49
 */

public class Pipe {
    public static void main(String[] args) throws Exception {
        PipedWriter writer=new PipedWriter();
        PipedReader reader=new PipedReader();
        writer.connect(reader);
        Thread printThread=new Thread(new Print((reader)),"PrintThread");
        printThread.start();
        int receive=0;
        try{
            while ((receive=System.in.read())!=-1){
                writer.write(receive);
            }
        }finally {
            writer.close();
        }
    }
    static class Print implements Runnable {
        private PipedReader in;
        public Print(PipedReader in) {
            this.in = in;
        }
        public void run() {
            int receive = 0;
            try {
                while ((receive = in.read()) != -1) {
                    System.out.print((char) receive);
                }
            } catch (IOException ex) {
            }
        }
    }
}
